var express = require('express')
var path = require('path')
var cookieParser = require('cookie-parser')
var logger = require('morgan')
const bodyParser = require('body-parser')

// 导入cors包
const cors = require('cors')

const loginRouter = require('./routes/login')
const blogRouter = require('./routes/blog')
const blogArticleRouter = require('./routes/blogArticle')
const pictureRouter = require('./routes/picture')
const uploadRouter = require('./routes/upload')
//
const categoryRouter = require('./routes/category')
const commentRouter = require('./routes/comment')
const pieChartRouter = require('./routes/pieChart')
const barChartRouter = require('./routes/barChart')
var app = express()
// 增大可传递的数据大小值
app.use(bodyParser.json({ limit: '50mb' }))
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }))

//静态伺服
app.use(express.static('page'))

// 注册全局中间件
app.use(cors())
app.use(logger('dev'))
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())
app.use(express.static(path.join(__dirname, 'public')))

//
app.use('/login', loginRouter)
app.use('/blog', blogRouter)
app.use('/blogArticle', blogArticleRouter)
app.use('/picture', pictureRouter)
app.use('/upload', uploadRouter)

//
app.use('/category', categoryRouter)
app.use('/comment', commentRouter)
app.use('/pieChart', pieChartRouter)
app.use('/barChart', barChartRouter)

module.exports = app
